local prevhealthP1 = "HealthState_Alive"
local prevhealthP2 = "HealthState_Alive"


return Def.ActorFrame{
	Def.ActorFrame{
		Name="DeadP1";
		Def.ActorFrame{
			BeginCommand=function(self)
				local style = GAMESTATE:GetCurrentStyle()
				local styleType = style:GetStyleType()
				self:visible( styleType ~= "StyleType_OnePlayerTwoSides" and styleType ~= "StyleType_TwoPlayersSharedSides" )
			end;
			HealthStateChangedMessageCommand=function(self, param)
				if param.PlayerNumber == PLAYER_1 then
					if param.HealthState == "HealthState_Dead" then
						self:RunCommandsOnChildren(cmd(playcommand,"Show"))
						prevHealthP1 = "HealthState_Dead"
					else
						if param.HealthState == "HealthState_Danger" and prevHealthP1 == "HealthState_Dead" then
							self:RunCommandsOnChildren(cmd(playcommand,"Hide"))
							prevHealthP1 = "HealthState_Danger"
						end
					end
				end
			end;
			-- SFX
			LoadActor("_blazed") .. {
				ShowCommand=cmd(play);
			};
			-- Player 1 Center
			LoadActor("_widechar")..{
				Name="DeadP1";
				Condition=Center1Player() == true;
				InitCommand=cmd(stretchto,SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM+50;diffusealpha,0.6;croptop,1;player,PLAYER_1);
				ShowCommand=cmd(croptop,1;diffusealpha,0.6;finishtweening;linear,0.6;croptop,0);
				HideCommand=cmd(finishtweening;linear,2;diffusealpha,0);
			};
			LoadActor("_fire")..{
				Name="DeadP1";
				Condition=Center1Player() == true;
				InitCommand=cmd(x,SCREEN_CENTER_X;y,SCREEN_BOTTOM+100;zoomtowidth,SCREEN_WIDTH;zoomy,3.5;fadebottom,0.1;diffusealpha,0;blend,'BlendMode_Add';player,PLAYER_1);
				ShowCommand=cmd(finishtweening;diffusealpha,1;linear,0.6;addy,-630;linear,0.1;diffusealpha,0);
				HideCommand=cmd(finishtweening;y,SCREEN_BOTTOM+100);
			};
			-- Player 1 Side
			LoadActor("_charred")..{
				Name="DeadP1";
				Condition=Center1Player() == false;
				InitCommand=cmd(draworder,100;faderight,0.1;stretchto,SCREEN_LEFT,SCREEN_TOP,SCREEN_CENTER_X,SCREEN_BOTTOM+170;diffusealpha,0.6;croptop,1;player,PLAYER_1);
				ShowCommand=cmd(croptop,1;diffusealpha,0.6;finishtweening;linear,0.6;croptop,0);
				HideCommand=cmd(finishtweening;linear,2;diffusealpha,0);
			};
			LoadActor("_fire")..{
				Name="DeadP1";
				Condition=Center1Player() == false;
				InitCommand=cmd(draworder,101;faderight,0.1;stretchto,SCREEN_LEFT,SCREEN_BOTTOM-250,SCREEN_CENTER_X,SCREEN_BOTTOM;y,SCREEN_BOTTOM+230;fadebottom,0.1;diffusealpha,0;blend,'BlendMode_Add';player,PLAYER_1);
				ShowCommand=cmd(finishtweening;diffusealpha,1;linear,0.6;addy,-730;linear,0.1;diffusealpha,0);
				HideCommand=cmd(finishtweening;y,SCREEN_BOTTOM+250);
			};
		};
	};


	Def.ActorFrame{
		Name="DeadP2";
		Def.ActorFrame{
			BeginCommand=function(self)
				local style = GAMESTATE:GetCurrentStyle()
				local styleType = style:GetStyleType()
				self:visible( styleType ~= "StyleType_OnePlayerTwoSides" and styleType ~= "StyleType_TwoPlayersSharedSides" )
			end;
			HealthStateChangedMessageCommand=function(self, param)
				if param.PlayerNumber == PLAYER_2 then
					if param.HealthState == "HealthState_Dead" then
						self:RunCommandsOnChildren(cmd(playcommand,"Show"))
						prevHealthP2 = "HealthState_Dead"
					else
						if param.HealthState == "HealthState_Danger" and prevHealthP2 == "HealthState_Dead" then
							self:RunCommandsOnChildren(cmd(playcommand,"Hide"))
							prevHealthP2 = "HealthState_Danger"
						end
					end
				end
			end;
			-- SFX
			LoadActor("_blazed") .. {
				ShowCommand=cmd(play);
			};
			-- Player 2 Center
			LoadActor("_widechar")..{
				Name="DeadP2";
				Condition=Center1Player() == true;
				InitCommand=cmd(stretchto,SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM+50;diffusealpha,0.6;croptop,1;player,PLAYER_2);
				ShowCommand=cmd(diffusealpha,0.6;croptop,1;finishtweening;linear,0.6;croptop,0);
				HideCommand=cmd(finishtweening;linear,2;diffusealpha,0);
			};
			LoadActor("_fire")..{
				Name="DeadP2";
				Condition=Center1Player() == true;
				InitCommand=cmd(x,SCREEN_CENTER_X;y,SCREEN_BOTTOM+50;zoomtowidth,SCREEN_WIDTH;zoomy,4;fadebottom,0.1;diffusealpha,0;blend,'BlendMode_Add';player,PLAYER_2);
				ShowCommand=cmd(finishtweening;diffusealpha,1;linear,0.6;addy,-630;linear,0.1;diffusealpha,0);
				HideCommand=cmd(finishtweening;y,SCREEN_BOTTOM+100);
			};
			-- Player 2 Side
			LoadActor("_charred")..{
				Name="DeadP2";
				Condition=Center1Player() == false;
				InitCommand=cmd(fadeleft,0.1;stretchto,SCREEN_CENTER_X,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM+170;diffusealpha,0.6;croptop,1;player,PLAYER_2);
				ShowCommand=cmd(croptop,1;diffusealpha,0.6;finishtweening;linear,0.6;croptop,0);
				HideCommand=cmd(finishtweening;linear,2;diffusealpha,0);
			};
			LoadActor("_fire")..{
				Name="DeadP2";
				Condition=Center1Player() == false;
				InitCommand=cmd(fadeleft,0.1;stretchto,SCREEN_CENTER_X,SCREEN_BOTTOM-250,SCREEN_RIGHT,SCREEN_BOTTOM;y,SCREEN_BOTTOM+250;fadebottom,0.1;diffusealpha,0;blend,'BlendMode_Add';player,PLAYER_2);
				ShowCommand=cmd(finishtweening;diffusealpha,1;linear,0.6;addy,-730;linear,0.1;diffusealpha,0);
				HideCommand=cmd(finishtweening;y,SCREEN_BOTTOM+250);
			};
		};
	};
};